'use strict';

App.controller('orderBackController', ['$rootScope', '$scope', 'Page', function($rootScope, $scope, Page) {

	$scope.orderBackGrid = {
		 column_defs: [
					{
					 	target : 8,
						template : function(row) {
							var html = '';
							if(parseFloat(row.refundMoney) > 0) {
								html += '<span>' + row.refundMoney + '</span>'
							} else {
								html += '<span>0</span>'
							}
							return html;
						}
					},
		   	        {
		   	            target: 9,
		   	            buttons: [
		   	                {
		   	                    name: '订单详情',
		   	                    class: 'btn purple',
		   	                    icon: 'fa-cog',
		   	                    event: 'showDetail'
		   	                },{
		   	                    name: '退款',
		   	                    class: 'btn btn-success',
		   	                    icon: 'fa-gavel',
		   	                    event: 'agree',
		   	                    visiable: function(row) {
		                         	if(row.orderBackStatus=='9' || row.orderBackStatus=='10' || row.orderBackStatus=='20'){// 9:退款处理中  10:退款成功 20:退款驳回
		                         		 return false;
		                         	}else {
		                         		 return true;
		                         	}
		                         }
		   	                },{
		   	                    name: '退款驳回',
		   	                    class: 'btn btn-danger',
		   	                    icon: 'fa-mail-reply',
		   	                    event: 'reject',
		   	                    visiable: function(row) {
		                         	if(row.orderBackStatus=='9' || row.orderBackStatus=='10' || row.orderBackStatus=='20'){// 9:退款处理中  10:退款成功 20:退款驳回
		                         		 return false;
		                         	}else {
		                         		 return true;
		                         	}
		                         }
		   	                }
		   	            ]
		   	        }
		       	],
		agree: function(row) {// 同意退款申请(可批量)
			 var param = {};
			 param.orderBackId = row.orderBackId;
			 Page.ajaxPost('orderBack/agree.do', param, function (resp) {
				 	var data =resp.data;
				 	if(data.payStatus == undefined || data.payStatus =='10' || data == undefined || data ==null){// 退款成功
				 		 Page.notice('退款成功!');
				 	}else {
				 		 Page.notice('退款失败!');
				 	}
		            $scope.orderBackGrid.query();
		        });
		},
		reject: function(row) {// 驳回退款申请(可批量)
			 var param = {};
			 param.orderBackId = row.orderBackId;
			 Page.ajaxPost('orderBack/reject.do', param, function (resp) {
	                Page.notice('退款申请已驳回!');
	                $scope.orderBackGrid.query();
	            });
		},
		showDetail : function(row){
			 var param = {};
			 $scope.orderBack = row;
			 param.orderBackId = row.orderBackId;
			 Page.ajaxPost('orderBack/getOrderBackDetailById.do', param, function (resp) {
				 $scope.orderBackDetailList = resp.data.passengers;
				 $scope.modal.show();
	            });
		}
	};
}]);

